package com.argrace.smart.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.argrace.smart.R;
import com.argrace.smart.fragment.RoomFragment;
import com.argrace.smart.model.LocalDb_RoomNameTable;

import java.util.ArrayList;

/**
 * Created by argrace_dev_1 on 2018/3/2.
 */

public class MyRoomAdapter extends BaseAdapter {
    private Context context;
    ArrayList<LocalDb_RoomNameTable> lists;

    public MyRoomAdapter(Context context, ArrayList<LocalDb_RoomNameTable> lists) {
        this.context = context;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        if (lists == null) {
            return 0;
        } else {
            return lists.size();
        }
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_room, parent, false); //加载布局
            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.item_room_text);
            holder.img = (ImageView) convertView.findViewById(R.id.item_room_img);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name.setText(lists.get(position).getRoomName());
        return convertView;
    }

    class ViewHolder {
        TextView name;
        ImageView img;
    }
}
